package application;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.sql.SQLException;
import java.util.ArrayList;


import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import framework.*;

public class PlayerFrame extends JFrame{

	/**
	 * The serial number.
	 */
	private static final long serialVersionUID = 1L;

	
	
	
	/**
	 * Width of the current song list in pixels.
	 */
	static private int CRT_LIST_WIDTH = 245;
	
	/**
	 * Visible rows in the current song list.
	 */
	static private int CRT_LIST_ROWS = 28;
	
	/**
	 * Width of the list of song lists in pixels.
	 */
	static private int SONG_LISTS_WIDTH = 100;
	
	/**
	 * Visible rows in the list of song lists.
	 */
	static private int SONG_LISTS_ROWS = 22;
	
	/**
	 * Visible rows in the lyrics area.
	 */
	static private int LYRICS_ROWS = 25;
	
	/**
	 * Visible columns in the lyrics area.
	 */
	static private int LYRICS_COLS = 32;
	
	/**
	 * Input window width in pixels.
	 */
	static private int INPUT_WIDTH = 300;

	/**
	 * Input window height in pixels.
	 */
	static private int INPUT_HEIGHT = 170;
	
	/**
	 * Width of the select list of song lists in pixels.
	 */
	static private int SELECT_LISTS_WIDTH = 100;
	
	/**
	 * Visible rows in the select list of song lists.
	 */
	static private int SELECT_LISTS_ROWS = 10;
	
	/**
	 * Select window width in pixels.
	 */
	static private int SELECT_WIDTH = 300;

	/**
	 * Select window height in pixels.
	 */
	static private int SELECT_HEIGHT = 350;
	
	/**
	 * Source path.
	 */
	private String path = System.getProperty("user.dir");
	
	private JList<Song> catalogList;
	private JList<SongList> songLists;
	private SongList currentList;
	private JButton btnLast;
	private JButton btnNext;
	private JButton btnPlay;
	private JButton btnRemoveList;
	private JButton btnAddList;
	private JButton btnRemoveSong;
	private JButton btnAddSong;
	private JButton btnPlayList;
	private JButton btnCurrentList;
	private JRadioButton btnOrderPlay;
	private JRadioButton btnRandomPlay;
	private JRadioButton btnLoopPlay;
	private JLabel songNameLabel;
	private JLabel userNameLabel;
	private JTextArea currentLyrics;
	private Thread thread;
	
	private User user;
	private PlayerDB db;
	private Song currentSong;
	private PlayFormatter playFormatter = OrderPlayFormatter.getSingletonInstance();
	private boolean isPlaying = false;
	
	
	
	public PlayerFrame(String userName,String password) throws SQLException, InterruptedException {
		
		db = new PlayerDB(userName,password);
		user = new User(userName,password);
		
		catalogList = new JList<Song>();
		songLists = new JList<SongList>();
		catalogList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		catalogList.setFixedCellWidth(CRT_LIST_WIDTH);
		catalogList.setVisibleRowCount(CRT_LIST_ROWS);
		songLists.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		songLists.setFixedCellWidth(SONG_LISTS_WIDTH);
		songLists.setVisibleRowCount(SONG_LISTS_ROWS);
		
		
		
		btnLast = new JButton("上一首");
		btnNext = new JButton("下一首");
		btnPlay = new JButton("播放/暂停");
		btnAddList = new JButton("创建歌单");
		btnRemoveList = new JButton("删除歌单");
		btnCurrentList = new JButton("当前播放列表");
		btnAddSong = new JButton("加入歌单");
		btnRemoveSong = new JButton("移出歌单");
		btnPlayList = new JButton("播放此歌单");
		btnOrderPlay = new JRadioButton("顺序播放",true);
		btnLoopPlay = new JRadioButton("单曲循环");
		btnRandomPlay = new JRadioButton("随机播放");
		
		ButtonGroup btnGroup = new ButtonGroup();
		btnGroup.add(btnOrderPlay);
		btnGroup.add(btnLoopPlay);
		btnGroup.add(btnRandomPlay);
		
		currentLyrics = new JTextArea(LYRICS_ROWS,LYRICS_COLS);
		currentLyrics.setEditable(false);
		
		start();
		
		songNameLabel = new JLabel("当前歌曲：" + currentSong.toString());
		songNameLabel.setBorder(BorderFactory.createTitledBorder(""));
		userNameLabel = new JLabel("当前账号：" + user.getName()); 
		userNameLabel.setBorder(BorderFactory.createTitledBorder(""));
		
		btnCurrentList.setVisible(true);
		btnAddSong.setVisible(false);
		btnRemoveSong.setVisible(false);
		btnPlayList.setVisible(false);
		
		
		/**
		 * The list of song lists panel.
		 */
		JPanel songListsPanel = new JPanel();
		songListsPanel.setBorder(BorderFactory.createTitledBorder("歌单"));
		songListsPanel.add(new JScrollPane(songLists, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
		
		/**
		 * The current song list panel.
		 */
		JPanel catalogListPanel = new JPanel();
		catalogListPanel.setBorder(BorderFactory.createTitledBorder("歌曲"));
		catalogListPanel.add(new JScrollPane(catalogList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
		
		/**
		 * The list of song lists and the current song list panel.
		 */
		JPanel listPanel = new JPanel(new BorderLayout());
		listPanel.add(songListsPanel,"West");
		listPanel.add(catalogListPanel,"Center");
		
		JPanel lyricsPanel = new JPanel(new BorderLayout());
		JPanel textPanel = new JPanel();
		textPanel.add(new JScrollPane(currentLyrics, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
				JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
		lyricsPanel.add(textPanel,"South");
		lyricsPanel.add(userNameLabel,"Center");
		
		JPanel buttonPanel = new JPanel();
		buttonPanel.add(btnOrderPlay);
		buttonPanel.add(btnLoopPlay);
		buttonPanel.add(btnRandomPlay);
		buttonPanel.add(btnAddList);
		buttonPanel.add(btnRemoveList);
		
		JPanel buttonPanel2 = new JPanel();
		buttonPanel2.add(btnCurrentList);
		buttonPanel2.add(btnPlayList);
		buttonPanel2.add(btnAddSong);
		buttonPanel2.add(btnRemoveSong);
		
		JPanel controlPanel = new JPanel();
		controlPanel.add(btnLast);
		controlPanel.add(btnPlay);
		controlPanel.add(btnNext);
		
		JPanel leftPanel = new JPanel(new BorderLayout());
		leftPanel.add(buttonPanel,"North");
		leftPanel.add(listPanel,"Center");
		leftPanel.add(buttonPanel2,"South");
		
		JPanel rightPanel = new JPanel(new BorderLayout());
		rightPanel.add(lyricsPanel,"North");
		rightPanel.add(songNameLabel,"Center");
		rightPanel.add(controlPanel,"South");
		
		setLayout(new BorderLayout());
		add(leftPanel,"West");
		add(rightPanel,"Center");
		
		btnAddList.addActionListener(new AddSongListListener());
		btnRemoveList.addActionListener(new RemoveSongListListener());
		btnAddSong.addActionListener(new AddSongListener());
		btnRemoveSong.addActionListener(new RemoveSongListener());
		songLists.addListSelectionListener(new DisplaySongsListener());
		catalogList.addListSelectionListener(new ChooseSongListener());
		btnPlayList.addActionListener(new PlayListListener());
		btnCurrentList.addActionListener(new CurrentListListener());
		btnOrderPlay.addActionListener(new OrderPlayListener());
		btnPlay.addActionListener(new PlayOrPauseListener());

		
		
		
	}

	/**
	 * Load all of the songs and song lists to start.
	 */
	private void start() {
		
//		System.out.println(path);
		ArrayList<String> songListsName = db.showAllLists();
		ArrayList<ArrayList<String>> infoOfSongs;
		SongList tempList;
		String tempSongName;
		String tempSongSinger;
		String tempLyrics;
		String tempSongURL;
		
		
		
		for(String listName : songListsName) {
			
			tempList = new SongList(listName);
			
			infoOfSongs = db.getInfoOfSongs(listName);
//			System.out.println(listName);
			for(ArrayList<String> info : infoOfSongs) {
				
				tempSongName = info.get(0);
				tempSongSinger = info.get(1);
				tempLyrics = info.get(2);
				tempSongURL = info.get(3);
				
				tempList.addSong(new Song(tempSongName,tempSongSinger,tempSongURL,tempLyrics));
			}
			
			user.addList(tempList);
		
		}
		
//		System.out.println(songListsName.get(0));
		
//		currentList = user.getLists().get(0);
		currentList = user.getList("defaultlist");
//		System.out.println(currentList.getListName());
		currentSong = currentList.getSongForIndex(0);
		
		updateList();
		currentLyrics.setText(loadLyrics(currentSong.getLyrics()));

	}
	

	/**
	 * Load or update all the <code>SongList</code> of the user into <code>songLists</code>.
	 */
	private void updateList() {
		
		songLists.setListData(user.getLists());
		
	}
	
	
	private void play() throws UnsupportedAudioFileException, IOException, LineUnavailableException {
		
//		Thread thread;
		thread = new Thread(new Runnable() {
			
			@Override
				public void run() {	
					try {
						isPlaying = true;
						playFormatter.formatPlay(currentList);
						
					} catch (Exception e) {
						e.printStackTrace();
					}				
				}
			});
		thread.start();
		

	
	}
	
	@SuppressWarnings("deprecation")
	private void pause() {
		isPlaying = false;
		try {
		
			thread.stop();
//			playFormatter.formatPlay(currentList);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
//		isPlaying = false;
	}

	/**
	 * 
	 * This inner class processes <code>btnCurrentList</code> events.
	 *
	 */
	class CurrentListListener implements ActionListener {
		JFrame frame; 
		JLabel title;
		JButton confirm; 
		JList<Song> currentSongs;
		JPanel panel;
		JPanel btnPanel;
		public void actionPerformed(ActionEvent event) {
			frame = new JFrame();
			title = new JLabel("当前播放歌曲列表：");
			confirm = new JButton("确认");
			
			currentSongs = new JList<Song>();
			currentSongs.setListData(currentList.getSongs());
			currentSongs.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			currentSongs.setFixedCellWidth(SELECT_LISTS_WIDTH);
			currentSongs.setVisibleRowCount(SELECT_LISTS_ROWS);
			
			panel = new JPanel(new BorderLayout());
			btnPanel = new JPanel();
			
			btnPanel.add(confirm);
			panel.add(title,"North");
			panel.add(new JScrollPane(currentSongs, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
					JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),"Center");
			panel.add(btnPanel,"South");
			
			frame.add(panel);
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setSize(SELECT_WIDTH,SELECT_HEIGHT);
			frame.setResizable(true);
			frame.setVisible(true);
			frame.setLocationRelativeTo(null);
			
			confirm.addActionListener(new ConfirmListener());
		}
		
		/**
		 * 
		 * This inner class processes JButton <code>confirm</code> events in the current list frame.
		 *
		 */
		class ConfirmListener implements ActionListener {
			public void actionPerformed(ActionEvent event) {
				frame.dispose();
			}
		}
	}
	
	/**
	 * 
	 * This inner class processes <code>songLists</code> events.
	 *
	 */
	class DisplaySongsListener implements ListSelectionListener {
		
		public void valueChanged(ListSelectionEvent event) {
			
			
				SongList displayList = songLists.getSelectedValue();
				if(displayList == null) {
					return;
				}
				else {
					
					catalogList.setListData(displayList.getSongs());
					btnPlayList.setVisible(true);
				}
				
			
		}
	}
	
	class ChooseSongListener implements ListSelectionListener {
		
		public void valueChanged(ListSelectionEvent event) {
	
			btnRemoveSong.setVisible(true);
			btnAddSong.setVisible(true);
			
			if(catalogList.getSelectedValue() != null) {
				currentLyrics.setText(loadLyrics(catalogList.getSelectedValue().getLyrics()));
				songNameLabel.setText("当前歌曲：" + catalogList.getSelectedValue().toString());

			}
		}
	}
	
	
	/**
	 * 
	 * This inner class processes <code>btnOrderPlay</code> events.
	 *
	 */
	class OrderPlayListener implements ActionListener {
		
		public void actionPerformed(ActionEvent event) {
			playFormatter = OrderPlayFormatter.getSingletonInstance();
			try {
				play();
			} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
				e.printStackTrace();
			}
		}
		
	}
	
	/**
	 * This inner class processes <code>btnLoopPlay</code> events.
	 *
	 */
	class LoopPlayListener implements ActionListener {
		
		public void actionPerformed(ActionEvent event) {
			playFormatter = LoopPlayFormatter.getSingletonInstance();
			try {
				play();
			} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
				e.printStackTrace();
			}
		}
		
	}
	
	/**
	 * This inner class processes <code>btnRandomPlay</code> events.
	 *
	 */
	class RandomPlayListener implements ActionListener {
		
		public void actionPerformed(ActionEvent event) {
			playFormatter = RandomPlayFormatter.getSingletonInstance();
			try {
				play();
			} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
				e.printStackTrace();
			}
			
		}
		
	}
	
	/**
	 * 
	 * This inner class processes <code>btnAddList</code> events.
	 *
	 */
	class AddSongListListener implements ActionListener {
		
		JPanel inputPanel;
		JPanel buttonPanel;
		JLabel tipTitle;
		JLabel inputTitle;
		JTextField inputField;
		JButton btnConfirm;
		JButton btnCancel;
		JFrame inputFrame;
		
		
		public void actionPerformed(ActionEvent event) {
			
			inputPanel = new JPanel(new GridLayout(1,2,0,0));
			buttonPanel = new JPanel();
			tipTitle = new JLabel("创建新歌单");
			inputTitle = new JLabel("请输入新歌单名：");
			tipTitle.setHorizontalAlignment(SwingConstants.CENTER);
			inputTitle.setHorizontalAlignment(SwingConstants.CENTER);
			inputField = new JTextField();
			inputField.setSize(INPUT_WIDTH, INPUT_HEIGHT);
			btnConfirm = new JButton("确认");
			btnCancel = new JButton("取消");
			buttonPanel.add(btnConfirm);
			buttonPanel.add(btnCancel);
			inputPanel.add(inputTitle);
			inputPanel.add(inputField);

			
			
			inputFrame = new JFrame();
			inputFrame.setLayout(new GridLayout(3,1,0,0));
			inputFrame.add(tipTitle);
			inputFrame.add(inputPanel);
			inputFrame.add(buttonPanel);
			inputFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			inputFrame.setSize(INPUT_WIDTH,INPUT_HEIGHT);
			inputFrame.setResizable(true);
			inputFrame.setVisible(true);
			inputFrame.setLocationRelativeTo(null);
			
			btnConfirm.addActionListener(new AddListConfirmListener());
			btnCancel.addActionListener(new AddListCancelListener());
			
		}
		
		/**
		 * 
		 * This inner class processes <code>btnConfirm</code> events 
		 * in the <code>AddSongListListener</code> class.
		 *
		 */
		class AddListConfirmListener implements ActionListener {
			
			public void actionPerformed(ActionEvent event) {
				
				String name = inputField.getText();
				user.addList(new SongList(name));
				try {
					if(!db.addAList(name)) {
						System.out.println("创建失败");
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
				
				updateList();
				inputFrame.dispose();
				
			}
		}
		
		/**
		 * This inner class processes <code>btnCancel</code> events 
		 * in the <code>AddSongListListener</code> class.
		 *
		 */
		class AddListCancelListener implements ActionListener {
			
			public void actionPerformed(ActionEvent event) {
				
				inputFrame.dispose();
				
			}
		}
		
	}
	
	/**
	 * 
	 * This inner class processes <code>btnRemoveList</code> events. 
	 *
	 */
	class RemoveSongListListener implements ActionListener {
		
		JFrame warningFrame;
		
		public void actionPerformed(ActionEvent event) {
			
			warningFrame = new JFrame();
			warningFrame.setLocationRelativeTo(null);
			JLabel warningLabel1 = new JLabel("请先选择要移除的歌单！");
			JLabel warningLabel2 = new JLabel("移除成功！");
			JLabel warningLabel3 = new JLabel("移除失败，请重试！");
			JButton btnConfirm = new JButton("确认");
			JPanel warningPanel = new JPanel();
			warningFrame.setContentPane(warningPanel);
			warningFrame.setLocationRelativeTo(null);
			warningFrame.setVisible(false);
			btnConfirm.addActionListener(new ConfirmListener());
			
			SongList rList = songLists.getSelectedValue();
			
			if(rList == null) {
				warningPanel.add(warningLabel1);
				warningPanel.add(btnConfirm);
				warningFrame.setVisible(true);
			}
			
			else {
				
				try {
					
					if(!db.removeAList(rList.getListName())) {
						warningPanel.add(warningLabel3);
						warningPanel.add(btnConfirm);
						warningFrame.setVisible(true);
					}
					else {
						user.removeList(rList.getListName());
						warningPanel.add(warningLabel2);
						warningPanel.add(btnConfirm);
						warningFrame.setVisible(true);
						updateList();
					}
					
					
				} catch (Exception e) {
					e.printStackTrace();
				}

				
				warningPanel.add(warningLabel2);
				warningPanel.add(btnConfirm);
				warningFrame.setVisible(true);
			}
			
		}
		
		/**
		 * This inner class processes <code>btnConfirm</code> events 
		 * in the <code>RemoveSongListListener</code> class.
		 *
		 */
		class ConfirmListener implements ActionListener {
			
			public void actionPerformed(ActionEvent event) {
				
				warningFrame.dispose();
				
			}
			
		}
		
	}
	
	/**
	 * 
	 * This inner class processes <code>btnPlay</code> events.
	 *
	 */
	class PlayOrPauseListener implements ActionListener {
		public void actionPerformed(ActionEvent event) {
			if(isPlaying == false) {
				try {
					play();
				} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
					e.printStackTrace();
				}
			}
			else {
				pause();
			}
			
			
		}
	}
	
	/**
	 * 
	 * This inner class processes <code>btnPlayList</code> events.
	 *
	 */
	class PlayListListener implements ActionListener {
		public void actionPerformed(ActionEvent event) {
			
			SongList pList = songLists.getSelectedValue();
			currentList = pList;
			try {
				play();
			} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
				e.printStackTrace();
			}
		}
	}	
	
	/**
	 * 
	 * This inner class processes <code>btnAddSong</code> events.
	 *
	 */
	class AddSongListener implements ActionListener {
		
		JFrame frame; 
		JFrame warningFrame;
		JLabel reminder;
		JLabel warning;
		JButton cancel;
		JButton selectConfirm;
		JButton retry;
		JList<SongList> lists;
		JPanel panel;
		JPanel btnPanel;
		JPanel warningPanel;
		Song s;
		
		public void actionPerformed(ActionEvent event) {
			s = catalogList.getSelectedValue();
			frame = new JFrame();
			reminder = new JLabel("请选择要将歌曲加入的歌单：");
			cancel = new JButton("取消");
			selectConfirm = new JButton("确认");
			

			lists = new JList<SongList>();
			lists.setListData(user.getLists());
			lists.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
			lists.setFixedCellWidth(SELECT_LISTS_WIDTH);
			lists.setVisibleRowCount(SELECT_LISTS_ROWS);
			
			panel = new JPanel(new BorderLayout());
			btnPanel = new JPanel();
			
			btnPanel.add(selectConfirm);
			btnPanel.add(cancel);
			panel.add(reminder,"North");
			panel.add(new JScrollPane(lists, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
					JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),"Center");
			panel.add(btnPanel,"South");
			
			frame.add(panel);
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setSize(SELECT_WIDTH,SELECT_HEIGHT);
			frame.setResizable(true);
			frame.setVisible(true);
			frame.setLocationRelativeTo(null);
			frame.setVisible(true);
			
			cancel.addActionListener(new CancelListener());
			selectConfirm.addActionListener(new ConfirmListener());
		}
		
		/**
		 * 
		 * This inner class processes JButton <code>cancel</code> events in the selection frame.
		 *
		 */
		class CancelListener implements ActionListener {
			public void actionPerformed(ActionEvent event) {
				frame.dispose();
			}
		}
		
		/**
		 * 
		 * This inner class processes JButton <code>confirm</code> events in the selection frame.
		 *
		 */
		class ConfirmListener implements ActionListener {
			public void actionPerformed(ActionEvent event) {
				SongList l = lists.getSelectedValue();
				
				if(l == null || s == null) {
					warningFrame = new JFrame();
					warning = new JLabel("添加失败，请重试！");
					retry = new JButton("重试");
					warningPanel = new JPanel();
					warningPanel.add(warning);
					warningPanel.add(retry);
					warningFrame.add(warningPanel);
					warningFrame.setLocationRelativeTo(null);
					warningFrame.setVisible(true);
					retry.addActionListener(new RetryListener());
					
				}
				else {
					l.addSong(s);
					db.addSongToList(s, l.getListName());
					frame.dispose();
				}
			}
			
			/**
			 * 
			 * This inner class processes JButton <code>retry</code> events in the warning frame.
			 *
			 */
			class RetryListener implements ActionListener {
				public void actionPerformed(ActionEvent event) {
					warningFrame.dispose();
					frame.dispose();
					
				}
			}
			
		}
		
	}
	
	
	/**
	 * 
	 * This inner class processes <code>btnRemoveSong</code> events.
	 *
	 */
	class RemoveSongListener implements ActionListener {
		
		Song s;
		SongList l;
		
		JFrame warningFrame;
		JLabel warning;
		JButton retry;
		JPanel warningPanel;
		
		public void actionPerformed(ActionEvent event) {
			s = catalogList.getSelectedValue();
			l = songLists.getSelectedValue();
			
			if(l == null || s == null) {
				warningFrame = new JFrame();
				warning = new JLabel("移除失败，请重试！");
				retry = new JButton("重试");
				warningPanel = new JPanel();
				warningPanel.add(warning);
				warningPanel.add(retry);
				warningFrame.add(warningPanel);
				warningFrame.setLocationRelativeTo(null);
				warningFrame.setVisible(true);
				retry.addActionListener(new RetryListener());
			}
			else {
				
				l.removeSong(s.getName());
				db.removeSongFromList(s.getURL(), l.getListName());
				
				catalogList.setListData(l.getSongs());
			}
		}
		
		/**
		 * 
		 * his inner class processes JButton <code>retry</code> events in the warning frame.
		 *
		 */
		class RetryListener implements ActionListener {
			public void actionPerformed(ActionEvent event) {
				warningFrame.dispose();
				
			}
		}
	}
	
	
	/**
	 * Load the lyrics by the file.
	 * @param fileURL the url of the lyrics file.
	 * @return the lyrics, a String.
	 */
	private String loadLyrics(String fileURL) {
		
		File lyricsFile = new File(path + fileURL);
		String line = null;
		String lyrics = "";
		if(lyricsFile.exists()) {
			try {
				
				BufferedReader br =new BufferedReader(new InputStreamReader(new FileInputStream(lyricsFile),"UTF-8") );
				
				while ((line = br.readLine()) != null ) {
					lyrics += line;
					lyrics += "\n";
				}
				
				br.close();
			} catch (IOException e) {
				e.getStackTrace();
			}
		}
		
		return lyrics;
		
	}
	
	
	
	
}